Prereq: "4.0"
*** ../tk4.0/patchlevel.h	Fri Jun 30 11:18:49 1995
--- patchlevel.h	Fri Jul 28 10:08:41 1995
***************
*** 17,23 ****
   * See the file "license.terms" for information on usage and redistribution
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   *
!  * @(#) patchlevel.h 1.7 95/06/30 11:18:45
   */
  
! #define TK_PATCH_LEVEL "4.0"
--- 17,23 ----
   * See the file "license.terms" for information on usage and redistribution
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   *
!  * @(#) patchlevel.h 1.8 95/07/18 16:23:42
   */
  
! #define TK_PATCH_LEVEL "4.0p1"
*** ../tk4.0/./tkSend.c	Thu Apr 20 16:27:00 1995
--- ./tkSend.c	Wed Jul 26 17:13:26 1995
***************
*** 12,18 ****
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkSend.c 1.48 95/04/20 16:26:59";
  
  #include "tkPort.h"
  #include "tkInt.h"
--- 12,18 ----
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkSend.c 1.49 95/07/26 17:13:25";
  
  #include "tkPort.h"
  #include "tkInt.h"
***************
*** 1771,1777 ****
      ckfree((char *) riPtr->name);
      riPtr->interp = NULL;
      UpdateCommWindow(riPtr->dispPtr);
!     Tk_EventuallyFree((ClientData) riPtr, free);
  }
  
  /*
--- 1771,1777 ----
      ckfree((char *) riPtr->name);
      riPtr->interp = NULL;
      UpdateCommWindow(riPtr->dispPtr);
!     Tk_EventuallyFree((ClientData) riPtr, (Tk_FreeProc *) free);
  }
  
  /*
*** ../tk4.0/./tkUnix.c	Sat Jun 24 17:14:32 1995
--- ./tkUnix.c	Fri Jun 30 14:59:41 1995
***************
*** 11,17 ****
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "%Z% %M% %I% %E% %U%";
  
  #include <tkInt.h>
  
--- 11,17 ----
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkUnix.c 1.1 95/06/30 14:59:42";
  
  #include <tkInt.h>
  
*** ../tk4.0/./tkWm.c	Wed Jun 28 17:38:54 1995
--- ./tkWm.c	Sat Jul 22 16:04:58 1995
***************
*** 13,19 ****
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkWm.c 1.105 95/06/28 17:38:53";
  
  #include "tkPort.h"
  #include "tkInt.h"
--- 13,19 ----
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkWm.c 1.107 95/07/22 16:04:57";
  
  #include "tkPort.h"
  #include "tkInt.h"
***************
*** 3575,3589 ****
       *     toplevels themselves aren't siblings).
       * The only solution I can see is to switch to using the window
       * itself instead of its frame, if there's no sibling, but use
!      * the frames if there's a sibling.  This means that raising
       * relative to a sibling won't work under olvwm.
       */
  
-     if (!(mask & CWSibling)) {
- 	window = winPtr->window;
-     }
      serial = NextRequest(winPtr->display);
!     XConfigureWindow(winPtr->display, window, mask, &changes);
  
      /*
       * Wait for the reconfiguration to complete.  If we don't wait, then
--- 3575,3587 ----
       *     toplevels themselves aren't siblings).
       * The only solution I can see is to switch to using the window
       * itself instead of its frame, if there's no sibling, but use
!      * the frame if there's a sibling.  This means that raising
       * relative to a sibling won't work under olvwm.
       */
  
      serial = NextRequest(winPtr->display);
!     XConfigureWindow(winPtr->display,
! 	    (mask & CWSibling) ? window : winPtr->window, mask, &changes);
  
      /*
       * Wait for the reconfiguration to complete.  If we don't wait, then
*** ../tk4.0/./tkButton.c	Fri Jun  9 08:20:07 1995
--- ./tkButton.c	Sat Jul 22 16:05:26 1995
***************
*** 13,19 ****
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkButton.c 1.119 95/06/09 08:19:59";
  
  #include "default.h"
  #include "tkPort.h"
--- 13,19 ----
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkButton.c 1.120 95/07/22 16:05:25";
  
  #include "default.h"
  #include "tkPort.h"
***************
*** 1690,1696 ****
      if (flags & TCL_TRACE_UNSETS) {
  	butPtr->flags &= ~SELECTED;
  	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
! 	    Tcl_TraceVar2(interp, name1, name2,
  		    TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
  		    ButtonVarProc, clientData);
  	}
--- 1690,1696 ----
      if (flags & TCL_TRACE_UNSETS) {
  	butPtr->flags &= ~SELECTED;
  	if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) {
! 	    Tcl_TraceVar(interp, butPtr->selVarName,
  		    TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
  		    ButtonVarProc, clientData);
  	}
***************
*** 1702,1708 ****
       * the button.
       */
  
!     value = Tcl_GetVar2(interp, name1, name2, flags & TCL_GLOBAL_ONLY);
      if (strcmp(value, butPtr->onValue) == 0) {
  	if (butPtr->flags & SELECTED) {
  	    return (char *) NULL;
--- 1702,1711 ----
       * the button.
       */
  
!     value = Tcl_GetVar(interp, butPtr->selVarName, TCL_GLOBAL_ONLY);
!     if (value == NULL) {
! 	value = "";
!     }
      if (strcmp(value, butPtr->onValue) == 0) {
  	if (butPtr->flags & SELECTED) {
  	    return (char *) NULL;
*** ../tk4.0/./tkListbox.c	Fri Jun 23 08:46:15 1995
--- ./tkListbox.c	Tue Jul 25 12:50:15 1995
***************
*** 12,18 ****
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkListbox.c 1.96 95/06/23 08:46:14";
  
  #include "tkPort.h"
  #include "default.h"
--- 12,18 ----
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkListbox.c 1.97 95/07/25 12:50:13";
  
  #include "tkPort.h"
  #include "default.h"
***************
*** 491,497 ****
  		i++, elPtr = elPtr->nextPtr) {
  	    /* Empty loop body. */
  	}
! 	if ((index >= listPtr->topIndex)
  		    && (index < (listPtr->topIndex + listPtr->fullLines
  		    + listPtr->partialLine))) {
  	    x = listPtr->inset - listPtr->xOffset;
--- 491,497 ----
  		i++, elPtr = elPtr->nextPtr) {
  	    /* Empty loop body. */
  	}
! 	if ((index >= listPtr->topIndex) && (index < listPtr->numElements)
  		    && (index < (listPtr->topIndex + listPtr->fullLines
  		    + listPtr->partialLine))) {
  	    x = listPtr->inset - listPtr->xOffset;
*** ../tk4.0/./tkMenu.c	Sun Jun 25 16:11:07 1995
--- ./tkMenu.c	Sat Jul 22 16:05:26 1995
***************
*** 13,19 ****
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkMenu.c 1.92 95/06/25 16:11:06";
  
  #include "tkPort.h"
  #include "default.h"
--- 13,19 ----
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkMenu.c 1.93 95/07/22 16:05:23";
  
  #include "tkPort.h"
  #include "default.h"
***************
*** 2368,2373 ****
--- 2368,2376 ----
       */
  
      value = Tcl_GetVar(interp, mePtr->name, TCL_GLOBAL_ONLY);
+     if (value == NULL) {
+ 	value = "";
+     }
      if (strcmp(value, mePtr->onValue) == 0) {
  	if (mePtr->flags & ENTRY_SELECTED) {
  	    return (char *) NULL;
*** ../tk4.0/./tkCanvas.c	Tue Jun 20 14:26:15 1995
--- ./tkCanvas.c	Thu Jul 27 13:23:50 1995
***************
*** 12,18 ****
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkCanvas.c 1.98 95/06/20 14:26:12";
  
  #include "default.h"
  #include "tkInt.h"
--- 12,18 ----
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkCanvas.c 1.101 95/07/27 13:23:48";
  
  #include "default.h"
  #include "tkInt.h"
***************
*** 1726,1732 ****
      borders:
      if (canvasPtr->flags & REDRAW_BORDERS) {
  	canvasPtr->flags &= ~REDRAW_BORDERS;
! 	if (canvasPtr->relief != TK_RELIEF_FLAT) {
  	    Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin),
  		    canvasPtr->bgBorder, canvasPtr->highlightWidth,
  		    canvasPtr->highlightWidth,
--- 1726,1732 ----
      borders:
      if (canvasPtr->flags & REDRAW_BORDERS) {
  	canvasPtr->flags &= ~REDRAW_BORDERS;
! 	if (canvasPtr->borderWidth > 0) {
  	    Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin),
  		    canvasPtr->bgBorder, canvasPtr->highlightWidth,
  		    canvasPtr->highlightWidth,
***************
*** 1791,1800 ****
  	Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr, x, y,
  		x + eventPtr->xexpose.width,
  		y + eventPtr->xexpose.height);
! 	if ((x < canvasPtr->inset) || (y < canvasPtr->inset)
! 		|| ((x + eventPtr->xexpose.width)
  		    > (Tk_Width(canvasPtr->tkwin) - canvasPtr->inset))
! 		|| ((y + eventPtr->xexpose.height)
  		    > (Tk_Height(canvasPtr->tkwin) - canvasPtr->inset))) {
  	    canvasPtr->flags |= REDRAW_BORDERS;
  	}
--- 1791,1801 ----
  	Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr, x, y,
  		x + eventPtr->xexpose.width,
  		y + eventPtr->xexpose.height);
! 	if ((eventPtr->xexpose.x < canvasPtr->inset)
! 		|| (eventPtr->xexpose.y < canvasPtr->inset)
! 		|| ((eventPtr->xexpose.x + eventPtr->xexpose.width)
  		    > (Tk_Width(canvasPtr->tkwin) - canvasPtr->inset))
! 		|| ((eventPtr->xexpose.y + eventPtr->xexpose.height)
  		    > (Tk_Height(canvasPtr->tkwin) - canvasPtr->inset))) {
  	    canvasPtr->flags |= REDRAW_BORDERS;
  	}
***************
*** 1818,1825 ****
  	 */
  
  	CanvasSetOrigin(canvasPtr, canvasPtr->xOrigin, canvasPtr->yOrigin);
! 	Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr, 0, 0,
! 		Tk_Width(canvasPtr->tkwin), Tk_Height(canvasPtr->tkwin));
  	canvasPtr->flags |= REDRAW_BORDERS;
      } else if (eventPtr->type == FocusIn) {
  	if (eventPtr->xfocus.detail != NotifyInferior) {
--- 1819,1828 ----
  	 */
  
  	CanvasSetOrigin(canvasPtr, canvasPtr->xOrigin, canvasPtr->yOrigin);
! 	Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr, canvasPtr->xOrigin,
! 		canvasPtr->yOrigin,
! 		canvasPtr->xOrigin + Tk_Width(canvasPtr->tkwin),
! 		canvasPtr->yOrigin + Tk_Height(canvasPtr->tkwin));
  	canvasPtr->flags |= REDRAW_BORDERS;
      } else if (eventPtr->type == FocusIn) {
  	if (eventPtr->xfocus.detail != NotifyInferior) {
***************
*** 3476,3482 ****
  
      range = object2 - object1;
      if (range <= 0) {
! 	f1 = f2 = 1.0;
      } else {
  	f1 = (screen1 - object1)/range;
  	if (f1 < 0) {
--- 3479,3486 ----
  
      range = object2 - object1;
      if (range <= 0) {
! 	f1 = 0;
! 	f2 = 1.0;
      } else {
  	f1 = (screen1 - object1)/range;
  	if (f1 < 0) {
*** ../tk4.0/./tkImgFmtPPM.c	Wed Jun 14 22:49:55 1995
--- ./tkImgFmtPPM.c	Wed Jul 26 12:57:37 1995
***************
*** 14,20 ****
   *	   Australian National University.
   */
  
! static char sccsid[] = "@(#) tkImgFmtPPM.c 1.7 95/06/14 22:49:55";
  
  #include "tkInt.h"
  #include "tkPort.h"
--- 14,20 ----
   *	   Australian National University.
   */
  
! static char sccsid[] = "@(#) tkImgFmtPPM.c 1.8 95/07/26 12:57:36";
  
  #include "tkInt.h"
  #include "tkPort.h"
***************
*** 63,69 ****
   */
  
  static int		ReadPPMFileHeader _ANSI_ARGS_((FILE *f, int *widthPtr,
! 			    int *heightPtr));
  
  /*
   *----------------------------------------------------------------------
--- 63,69 ----
   */
  
  static int		ReadPPMFileHeader _ANSI_ARGS_((FILE *f, int *widthPtr,
! 			    int *heightPtr, int *maxIntensityPtr));
  
  /*
   *----------------------------------------------------------------------
***************
*** 92,98 ****
  				 * returned here if the file is a valid
  				 * raw PPM file. */
  {
!     return ReadPPMFileHeader(f, widthPtr, heightPtr);
  }
  
  /*
--- 92,100 ----
  				 * returned here if the file is a valid
  				 * raw PPM file. */
  {
!     int dummy;
! 
!     return ReadPPMFileHeader(f, widthPtr, heightPtr, &dummy);
  }
  
  /*
***************
*** 130,141 ****
      int srcX, srcY;		/* Coordinates of top-left pixel to be used
  				 * in image being read. */
  {
!     int fileWidth, fileHeight;
      int nLines, nBytes, h, type, count;
      unsigned char *pixelPtr;
      Tk_PhotoImageBlock block;
  
!     type = ReadPPMFileHeader(f, &fileWidth, &fileHeight);
      if (type == 0) {
  	Tcl_AppendResult(interp, "couldn't read raw PPM header from file \"",
  		fileName, "\"", NULL);
--- 132,143 ----
      int srcX, srcY;		/* Coordinates of top-left pixel to be used
  				 * in image being read. */
  {
!     int fileWidth, fileHeight, maxIntensity;
      int nLines, nBytes, h, type, count;
      unsigned char *pixelPtr;
      Tk_PhotoImageBlock block;
  
!     type = ReadPPMFileHeader(f, &fileWidth, &fileHeight, &maxIntensity);
      if (type == 0) {
  	Tcl_AppendResult(interp, "couldn't read raw PPM header from file \"",
  		fileName, "\"", NULL);
***************
*** 146,152 ****
--- 148,163 ----
  		"\" has dimension(s) <= 0", (char *) NULL);
  	return TCL_ERROR;
      }
+     if ((maxIntensity <= 0) || (maxIntensity >= 256)) {
+ 	char buffer[30];
  
+ 	sprintf(buffer, "%d", maxIntensity);
+ 	Tcl_AppendResult(interp, "PPM image file \"", fileName,
+ 		"\" has bad maximum intensity value ", buffer,
+ 		(char *) NULL);
+ 	return TCL_ERROR;
+     }
+ 
      if ((srcX + width) > fileWidth) {
  	width = fileWidth - srcX;
      }
***************
*** 204,209 ****
--- 215,227 ----
  	    ckfree((char *) pixelPtr);
  	    return TCL_ERROR;
  	}
+ 	if (maxIntensity != 255) {
+ 	    unsigned char *p;
+ 
+ 	    for (p = pixelPtr; count > 0; count--, p++) {
+ 		*p = (((int) *p) * 255)/maxIntensity;
+ 	    }
+ 	}
  	block.height = nLines;
  	Tk_PhotoPutBlock(imageHandle, &block, destX, destY, width, nLines);
  	destY += nLines;
***************
*** 296,302 ****
   * ReadPPMFileHeader --
   *
   *	This procedure reads the PPM header from the beginning of a
!  *	PPM file and returns the dimensions of the image.
   *
   * Results:
   *	The return value is PGM if file "f" appears to start with
--- 314,320 ----
   * ReadPPMFileHeader --
   *
   *	This procedure reads the PPM header from the beginning of a
!  *	PPM file and returns information from the header.
   *
   * Results:
   *	The return value is PGM if file "f" appears to start with
***************
*** 303,309 ****
   *	a valid PGM header, PPM if "f" appears to start with a valid
   *      PPM header, and 0 otherwise.  If the header is valid,
   *	then *widthPtr and *heightPtr are modified to hold the
!  *	dimensions of the image.
   *
   * Side effects:
   *	The access position in f advances.
--- 321,328 ----
   *	a valid PGM header, PPM if "f" appears to start with a valid
   *      PPM header, and 0 otherwise.  If the header is valid,
   *	then *widthPtr and *heightPtr are modified to hold the
!  *	dimensions of the image and *maxIntensityPtr is modified to
!  *	hold the value of a "fully on" intensity value.
   *
   * Side effects:
   *	The access position in f advances.
***************
*** 312,323 ****
   */
  
  static int
! ReadPPMFileHeader(f, widthPtr, heightPtr)
      FILE *f;			/* Image file to read the header from */
      int *widthPtr, *heightPtr;	/* The dimensions of the image are
  				 * returned here. */
  {
-     int maxPixel;
  #define BUFFER_SIZE 1000
      char buffer[BUFFER_SIZE];
      int i, numFields, firstInLine, c;
--- 331,343 ----
   */
  
  static int
! ReadPPMFileHeader(f, widthPtr, heightPtr, maxIntensityPtr)
      FILE *f;			/* Image file to read the header from */
      int *widthPtr, *heightPtr;	/* The dimensions of the image are
  				 * returned here. */
+     int *maxIntensityPtr;	/* The maximum intensity value for
+ 				 * the image is stored here. */
  {
  #define BUFFER_SIZE 1000
      char buffer[BUFFER_SIZE];
      int i, numFields, firstInLine, c;
***************
*** 368,374 ****
      buffer[i] = 0;
  
      /*
!      * Parse the fields, which are: id, width, height, maxPixel.
       */
  
      if (strncmp(buffer, "P6 ", 3) == 0) {
--- 388,394 ----
      buffer[i] = 0;
  
      /*
!      * Parse the fields, which are: id, width, height, maxIntensity.
       */
  
      if (strncmp(buffer, "P6 ", 3) == 0) {
***************
*** 378,387 ****
      } else {
  	return 0;
      }
!     if (sscanf(buffer+3, "%d %d %d", widthPtr, heightPtr, &maxPixel) != 3) {
! 	return 0;
!     }
!     if (maxPixel != 255) {
  	return 0;
      }
      return type;
--- 398,405 ----
      } else {
  	return 0;
      }
!     if (sscanf(buffer+3, "%d %d %d", widthPtr, heightPtr, maxIntensityPtr)
! 	    != 3) {
  	return 0;
      }
      return type;
*** ../tk4.0/./tkImgPhoto.c	Wed Jun 21 15:47:02 1995
--- ./tkImgPhoto.c	Tue Jul 25 15:55:28 1995
***************
*** 16,22 ****
   *	   Australian National University.
   */
  
! static char sccsid[] = "@(#) tkImgPhoto.c 1.25 95/06/21 15:46:57";
  
  #include "tkInt.h"
  #include "tkPort.h"
--- 16,22 ----
   *	   Australian National University.
   */
  
! static char sccsid[] = "@(#) tkImgPhoto.c 1.27 95/07/25 15:55:25";
  
  #include "tkInt.h"
  #include "tkPort.h"
***************
*** 2128,2134 ****
      PhotoMaster *masterPtr;
      schar *newError;
      schar *errSrcPtr, *errDestPtr;
!     int h, offset, pitch;
      XRectangle validBox;
      Pixmap newPixmap;
  
--- 2128,2134 ----
      PhotoMaster *masterPtr;
      schar *newError;
      schar *errSrcPtr, *errDestPtr;
!     int h, offset;
      XRectangle validBox;
      Pixmap newPixmap;
  
***************
*** 2161,2168 ****
  	    || (instancePtr->height != masterPtr->height)
  	    || (instancePtr->error == NULL)) {
  
! 	pitch = masterPtr->width * sizeof(schar) * 3;
! 	newError = (schar *) ckalloc((unsigned) (masterPtr->height * pitch));
  
  	/*
  	 * Zero the new array so that we don't get bogus error values
--- 2161,2168 ----
  	    || (instancePtr->height != masterPtr->height)
  	    || (instancePtr->error == NULL)) {
  
! 	newError = (schar *) ckalloc((unsigned)
! 		(masterPtr->height * masterPtr->width * 3 * sizeof(schar)));
  
  	/*
  	 * Zero the new array so that we don't get bogus error values
***************
*** 2173,2187 ****
  	    && ((instancePtr->width == masterPtr->width)
  		|| (validBox.width == masterPtr->width))) {
  	    if (validBox.y > 0) {
! 		memset((VOID *) newError, 0, (size_t) (validBox.y * pitch));
  	    }
  	    h = validBox.y + validBox.height;
  	    if (h < masterPtr->height) {
! 		memset((VOID *) (newError + h * pitch), 0,
! 			(size_t) ((masterPtr->height - h) * pitch));
  	    }
  	} else {
! 	    memset((VOID *) newError, 0, (size_t) (masterPtr->height * pitch));
  	}
  
  	if (instancePtr->error != NULL) {
--- 2173,2190 ----
  	    && ((instancePtr->width == masterPtr->width)
  		|| (validBox.width == masterPtr->width))) {
  	    if (validBox.y > 0) {
! 		memset((VOID *) newError, 0, (size_t)
! 			(validBox.y * masterPtr->width * 3 * sizeof(schar)));
  	    }
  	    h = validBox.y + validBox.height;
  	    if (h < masterPtr->height) {
! 		memset((VOID *) (newError + h * masterPtr->width * 3), 0,
! 			(size_t) ((masterPtr->height - h)
! 			    * masterPtr->width * 3 * sizeof(schar)));
  	    }
  	} else {
! 	    memset((VOID *) newError, 0, (size_t)
! 		    (masterPtr->height * masterPtr->width * 3 * sizeof(schar)));
  	}
  
  	if (instancePtr->error != NULL) {
***************
*** 2193,2215 ****
  
  	    if (masterPtr->width == instancePtr->width) {
  
! 		offset = validBox.y * pitch;
  		memcpy((VOID *) (newError + offset),
  			(VOID *) (instancePtr->error + offset),
! 			(size_t) (validBox.height * pitch));
  
  	    } else if (validBox.width > 0 && validBox.height > 0) {
  
  		errDestPtr = newError
! 			+ validBox.y * pitch + validBox.x * 3 * sizeof(schar);
  		errSrcPtr = instancePtr->error
! 			+ (validBox.y * instancePtr->width + validBox.x)
! 			* 3 * sizeof(schar);
  		for (h = validBox.height; h > 0; --h) {
  		    memcpy((VOID *) errDestPtr, (VOID *) errSrcPtr,
  			    validBox.width * 3 * sizeof(schar));
! 		    errDestPtr += masterPtr->width * 3 * sizeof(schar);
! 		    errSrcPtr += instancePtr->width * 3 * sizeof(schar);
  		}
  	    }
  	    ckfree((char *) instancePtr->error);
--- 2196,2218 ----
  
  	    if (masterPtr->width == instancePtr->width) {
  
! 		offset = validBox.y * masterPtr->width * 3;
  		memcpy((VOID *) (newError + offset),
  			(VOID *) (instancePtr->error + offset),
! 			(size_t) (validBox.height
! 			* masterPtr->width * 3 * sizeof(schar)));
  
  	    } else if (validBox.width > 0 && validBox.height > 0) {
  
  		errDestPtr = newError
! 			+ (validBox.y * masterPtr->width + validBox.x) * 3;
  		errSrcPtr = instancePtr->error
! 			+ (validBox.y * instancePtr->width + validBox.x) * 3;
  		for (h = validBox.height; h > 0; --h) {
  		    memcpy((VOID *) errDestPtr, (VOID *) errSrcPtr,
  			    validBox.width * 3 * sizeof(schar));
! 		    errDestPtr += masterPtr->width * 3;
! 		    errSrcPtr += instancePtr->width * 3;
  		}
  	    }
  	    ckfree((char *) instancePtr->error);
***************
*** 2399,2404 ****
--- 2402,2419 ----
  	 */
  
  	colorPtr = (ColorTable *) ckalloc(sizeof(ColorTable));
+ 
+ 	/*
+ 	 * The following line of code should not normally be needed due
+ 	 * to the assignment in the following line.  However, it compensates
+ 	 * for bugs in some compilers (HP, for example) where
+ 	 * sizeof(ColorTable) is 24 but the assignment only copies 20 bytes,
+ 	 * leaving 4 bytes uninitialized;  these cause problems when using
+ 	 * the id for lookups in imgPhotoColorHash, and can result in
+ 	 * core dumps.
+ 	 */
+ 
+ 	memset((VOID *) &colorPtr->id, 0, sizeof(ColorTableId));
  	colorPtr->id = id;
  	colorPtr->flags = 0;
  	colorPtr->refCount = 0;
*** ../tk4.0/./tkText.c	Wed Jun 28 17:19:33 1995
--- ./tkText.c	Thu Jul 20 09:42:41 1995
***************
*** 14,20 ****
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkText.c 1.79 95/06/28 17:19:32";
  
  #include "default.h"
  #include "tkPort.h"
--- 14,20 ----
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkText.c 1.80 95/07/20 09:42:42";
  
  #include "default.h"
  #include "tkPort.h"
***************
*** 1632,1659 ****
  	firstChar = 0;
  	lastChar = INT_MAX;
  	if (lineNum == startingLine) {
  	    /*
  	     * The starting line is tricky: the first time we see it
  	     * we check one part of the line, and the second pass through
! 	     * we check the other part of the line.
  	     */
  
  	    passes++;
! 	    if (passes == 1) {
! 		if (backwards) {
! 		    lastChar = startingChar;
! 		} else {
! 		    firstChar = startingChar;
! 		    if (firstChar >= Tcl_DStringLength(&line)) {
! 			goto nextLine;
! 		    }
  		}
  	    } else {
! 		if (backwards) {
! 		    firstChar = startingChar;
! 		} else {
! 		    lastChar = startingChar;
! 		}
  	    }
  	}
  	do {
--- 1632,1674 ----
  	firstChar = 0;
  	lastChar = INT_MAX;
  	if (lineNum == startingLine) {
+ 	    int indexInDString;
+ 
  	    /*
  	     * The starting line is tricky: the first time we see it
  	     * we check one part of the line, and the second pass through
! 	     * we check the other part of the line.  We have to be very
! 	     * careful here because there could be embedded windows or
! 	     * other things that are not in the extracted line.  Rescan
! 	     * the original line to compute the index in it of the first
! 	     * character.
  	     */
  
+ 	    indexInDString = startingChar;
+ 	    for (segPtr = linePtr->segPtr, leftToScan = startingChar;
+ 		    leftToScan > 0; segPtr = segPtr->nextPtr) {
+ 		if (segPtr->typePtr != &tkTextCharType) {
+ 		    indexInDString -= segPtr->size;
+ 		}
+ 		leftToScan -= segPtr->size;
+ 	    }
+ 
  	    passes++;
! 	    if ((passes == 1) ^ backwards) {
! 		/*
! 		 * Only use the last part of the line.
! 		 */
! 
! 		firstChar = indexInDString;
! 		if (firstChar >= Tcl_DStringLength(&line)) {
! 		    goto nextLine;
  		}
  	    } else {
! 		/*
! 		 * Use only the first part of the line.
! 		 */
! 
! 		lastChar = indexInDString;
  	    }
  	}
  	do {
*** ../tk4.0/./tkTextBTree.c	Tue Jan  3 17:06:50 1995
--- ./tkTextBTree.c	Fri Jul 28 10:07:06 1995
***************
*** 12,18 ****
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkTextBTree.c 1.25 95/01/03 17:06:15";
  
  #include "tkInt.h"
  #include "tkPort.h"
--- 12,18 ----
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkTextBTree.c 1.26 95/07/28 10:07:03";
  
  #include "tkInt.h"
  #include "tkPort.h"
***************
*** 715,721 ****
  		    prevNodePtr->nextPtr = curNodePtr->nextPtr;
  		}
  		parentPtr->numChildren--;
- 		DeleteSummaries(curNodePtr->summaryPtr);
  		ckfree((char *) curNodePtr);
  		curNodePtr = parentPtr;
  	    }
--- 715,720 ----
*** ../tk4.0/./tkTextDisp.c	Wed Jun 28 15:06:53 1995
--- ./tkTextDisp.c	Sat Jul 22 17:17:20 1995
***************
*** 12,18 ****
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkTextDisp.c 1.91 95/06/28 15:06:50";
  
  #include "tkPort.h"
  #include "tkInt.h"
--- 12,18 ----
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   */
  
! static char sccsid[] = "@(#) tkTextDisp.c 1.92 95/07/22 17:17:18";
  
  #include "tkPort.h"
  #include "tkInt.h"
***************
*** 2434,2439 ****
--- 2434,2460 ----
      TkTextIndex rounded;
  
      /*
+      * Schedule both a redisplay and a recomputation of display information.
+      * It's done here rather than the end of the procedure for two reasons:
+      *
+      * 1. If there are no display lines to update we'll want to return
+      *    immediately, well before the end of the procedure.
+      * 2. It's important to arrange for the redisplay BEFORE calling
+      *    FreeDLines.  The reason for this is subtle and has to do with
+      *    embedded windows.  The chunk delete procedure for an embedded
+      *    window will schedule an idle handler to unmap the window.
+      *    However, we want the idle handler for redisplay to be called
+      *    first, so that it can put the embedded window back on the screen
+      *    again (if appropriate).  This will prevent the window from ever
+      *    being unmapped, and thereby avoid flashing.
+      */
+ 
+     if (!(dInfoPtr->flags & REDRAW_PENDING)) {
+ 	Tk_DoWhenIdle(DisplayText, (ClientData) textPtr);
+     }
+     dInfoPtr->flags |= REDRAW_PENDING|DINFO_OUT_OF_DATE|REPICK_NEEDED;
+ 
+     /*
       * Find the DLines corresponding to index1Ptr and index2Ptr.  There
       * is one tricky thing here, which is that we have to relayout in
       * units of whole text lines:  round index1Ptr back to the beginning
***************
*** 2454,2475 ****
  	    && (lastPtr->index.linePtr == index2Ptr->linePtr)) {
  	lastPtr = lastPtr->nextPtr;
      }
- 
-     /*
-      * Schedule both a redisplay and a recomputation of display information.
-      * It's important to do this BEFORE calling FreeDLines.  The reason for
-      * this is subtle and has to do with embedded windows.  The chunk delete
-      * procedure for an embedded window will schedule an idle handler to
-      * unmap the window.  However, we want the idle handler for redisplay
-      * to be called first, so that it can put the embedded window back on
-      * the screen again (if appropriate).  This will prevent the window from
-      * ever being unmapped, and thereby avoid flashing.
-      */
- 
-     if (!(dInfoPtr->flags & REDRAW_PENDING)) {
- 	Tk_DoWhenIdle(DisplayText, (ClientData) textPtr);
-     }
-     dInfoPtr->flags |= REDRAW_PENDING|DINFO_OUT_OF_DATE|REPICK_NEEDED;
  
      /*
       * Delete all the DLines from firstPtr up to but not including lastPtr.
--- 2475,2480 ----
*** ../tk4.0/./tkText.h	Mon Apr 17 14:51:52 1995
--- ./tkText.h	Sat Jul 22 16:05:45 1995
***************
*** 10,16 ****
   * See the file "license.terms" for information on usage and redistribution
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   *
!  * @(#) tkText.h 1.35 95/04/17 14:51:44
   */
  
  #ifndef _TKTEXT
--- 10,16 ----
   * See the file "license.terms" for information on usage and redistribution
   * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
   *
!  * @(#) tkText.h 1.36 95/07/22 16:05:44
   */
  
  #ifndef _TKTEXT
***************
*** 634,642 ****
      Tk_SegLineChangeProc *lineChangeProc;
  					/* Invoked when a segment is about
  					 * to be moved from its current line
! 					 * to some other line (cleanupProc
! 					 * will be called later with the
! 					 * new line). */
      Tk_SegLayoutProc *layoutProc;	/* Returns size information when
  					 * figuring out what to display in
  					 * window. */
--- 634,644 ----
      Tk_SegLineChangeProc *lineChangeProc;
  					/* Invoked when a segment is about
  					 * to be moved from its current line
! 					 * to an earlier line because of
! 					 * a deletion.  The linePtr is that
! 					 * for the segment's old line.
! 					 * CleanupProc will be invoked after
! 					 * the deletion is finished. */
      Tk_SegLayoutProc *layoutProc;	/* Returns size information when
  					 * figuring out what to display in
  					 * window. */
*** ../tk4.0/./changes	Fri Jun 30 11:18:50 1995
--- ./changes	Fri Jul 28 10:20:44 1995
***************
*** 2,8 ****
  released on March 13, 1991.  Changes that aren't backward compatible
  are marked specially.
  
! sccsid = @(#) changes 1.21 95/06/30 11:18:48
  
  3/16/91 (bug fix) Modified tkWindow.c to remove Tk's Tcl commands from
  the interpreter when the main window is deleted (otherwise there will
--- 2,8 ----
  released on March 13, 1991.  Changes that aren't backward compatible
  are marked specially.
  
! sccsid = %Z% %M% %I% %E% %U%
  
  3/16/91 (bug fix) Modified tkWindow.c to remove Tk's Tcl commands from
  the interpreter when the main window is deleted (otherwise there will
***************
*** 2404,2406 ****
--- 2404,2455 ----
  slider.
  
  -------------------- Release 4.0, 7/1/95 -------------------------
+ 
+ 7/18/95 (bug fix) Changed "exec wish" lines in demo scripts to
+ "exec wish4.0" to avoid version conflicts.
+ 
+ 7/19/95 (bug fix) Fixed bug where 2-second delays were ocurring during
+ "raise" and "lower" commands for toplevel windows under some window
+ managers (such as fvwm).
+ 
+ 7/20/95 (bug fix) Text searches were misbehaving when there were embedded
+ windows on the starting line of the search.  The most common symptom is
+ that Tk would fail to find a match at the starting position for the
+ search.
+ 
+ 7/20/95 (bug fix) Fixed a couple of bugs in canvases that caused them
+ not to refresh properly in some cases (e.g. old borders were not properly
+ erased or redrawn after some resizes).
+ 
+ 7/22/95 (bug fix) Fixed core dump that could occur in menus if a checkbutton
+ entry's -variable option referred to an array (or couldn't be read
+ by the menu C code for some other reason).
+ 
+ 7/22/95 (bug fix) Text widgets didn't update their scrollbars when
+ changes were made to information that was off-screen.
+ 
+ 7/25/95 (bug fix) Fixed core-dump in tkListbox.c that used to happen
+ in the command ".l bbox end" if the listbox was empty.
+ 
+ 7/25/95 (bug fix) Page-up and page-down bindings for listboxes didn't
+ move active element to remain on the screen.
+ 
+ 7/25/95 (bug fix) Fixed bug in tkImgPhoto.c that caused core dumps
+ (during Tk self-tests and other image uses) on AIX and other machines
+ where "schar" in tkImgPhoto.c was being defined as "short" instead of
+ "char".
+ 
+ 7/26/95 (bug fix) The PPM image reader couldn't handle maximum intensity
+ values other than 255.
+ 
+ 7/26/95 (bug fix) Canvases didn't redraw their borders when the relief
+ changed from raised to flat.
+ 
+ 7/27/95 (bug fix) Canvases didn't set the scrolling values correctly
+ when no scroll region was specified.
+ 
+ 7/28/95 (bug fix) Modified menu and tk_dialog scripts to restore any
+ old grab that might have been in effect before a menu or dialog was
+ posted.
+ 
+ ----------------- Released patch 4.0p1, 7/29/95 ----------------------
*** ../tk4.0/./configure	Thu Jun 29 15:19:01 1995
--- ./configure	Tue Jul 25 17:30:46 1995
***************
*** 1,7 ****
  #! /bin/sh
  
  # Guess values for system-dependent variables and create Makefiles.
! # Generated automatically using autoconf version 2.2 
  # Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  #
  # This configure script is free software; the Free Software Foundation
--- 1,7 ----
  #! /bin/sh
  
  # Guess values for system-dependent variables and create Makefiles.
! # Generated automatically using autoconf version 2.4 
  # Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  #
  # This configure script is free software; the Free Software Foundation
***************
*** 218,224 ****
      verbose=yes ;;
  
    -version | --version | --versio | --versi | --vers)
!     echo "configure generated by autoconf version 2.2"
      exit 0 ;;
  
    -with-* | --with-*)
--- 218,224 ----
      verbose=yes ;;
  
    -version | --version | --versio | --versi | --vers)
!     echo "configure generated by autoconf version 2.4"
      exit 0 ;;
  
    -with-* | --with-*)
***************
*** 384,391 ****
  ac_ext=c
  # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
  ac_cpp='$CPP $CPPFLAGS'
! ac_compile='${CC-cc} conftest.$ac_ext $CFLAGS $CPPFLAGS -c 1>&5 2>&5'
! ac_link='${CC-cc} conftest.$ac_ext $CFLAGS $CPPFLAGS $LDFLAGS -o conftest $LIBS 1>&5 2>&5'
  
  if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
    # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
--- 384,391 ----
  ac_ext=c
  # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
  ac_cpp='$CPP $CPPFLAGS'
! ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5 2>&5'
! ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5 2>&5'
  
  if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
    # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
***************
*** 589,596 ****
  rm -f conftest*
    ac_cv_prog_CPP="$CPP"
  fi
  fi
- CPP="$ac_cv_prog_CPP"
  echo "$ac_t""$CPP" 1>&6
  
  for ac_hdr in unistd.h limits.h
--- 589,598 ----
  rm -f conftest*
    ac_cv_prog_CPP="$CPP"
  fi
+   CPP="$ac_cv_prog_CPP"
+ else
+   ac_cv_prog_CPP="$CPP"
  fi
  echo "$ac_t""$CPP" 1>&6
  
  for ac_hdr in unistd.h limits.h
***************
*** 601,607 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 605 "configure"
  #include "confdefs.h"
  #include <$ac_hdr>
  EOF
--- 603,609 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 607 "configure"
  #include "confdefs.h"
  #include <$ac_hdr>
  EOF
***************
*** 619,625 ****
  fi
  if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
    echo "$ac_t""yes" 1>&6
!     ac_tr_hdr=HAVE_`echo $ac_hdr | tr '[a-z]./\055' '[A-Z]___'`
    cat >> confdefs.h <<EOF
  #define $ac_tr_hdr 1
  EOF
--- 621,627 ----
  fi
  if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
    echo "$ac_t""yes" 1>&6
!     ac_tr_hdr=HAVE_`echo $ac_hdr | tr 'abcdefghijklmnopqrstuvwxyz./\055' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ___'`
    cat >> confdefs.h <<EOF
  #define $ac_tr_hdr 1
  EOF
***************
*** 642,648 ****
  
  echo $ac_n "checking fd_set and sys/select""... $ac_c" 1>&6
  cat > conftest.$ac_ext <<EOF
! #line 646 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  int main() { return 0; }
--- 644,650 ----
  
  echo $ac_n "checking fd_set and sys/select""... $ac_c" 1>&6
  cat > conftest.$ac_ext <<EOF
! #line 648 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  int main() { return 0; }
***************
*** 661,667 ****
  
  if test $tk_ok = no; then
      cat > conftest.$ac_ext <<EOF
! #line 665 "configure"
  #include "confdefs.h"
  #include <sys/select.h>
  EOF
--- 663,669 ----
  
  if test $tk_ok = no; then
      cat > conftest.$ac_ext <<EOF
! #line 667 "configure"
  #include "confdefs.h"
  #include <sys/select.h>
  EOF
***************
*** 694,700 ****
  
  echo $ac_n "checking stdlib.h""... $ac_c" 1>&6
  cat > conftest.$ac_ext <<EOF
! #line 698 "configure"
  #include "confdefs.h"
  #include <stdlib.h>
  EOF
--- 696,702 ----
  
  echo $ac_n "checking stdlib.h""... $ac_c" 1>&6
  cat > conftest.$ac_ext <<EOF
! #line 700 "configure"
  #include "confdefs.h"
  #include <stdlib.h>
  EOF
***************
*** 709,715 ****
  rm -f conftest*
  
  cat > conftest.$ac_ext <<EOF
! #line 713 "configure"
  #include "confdefs.h"
  #include <stdlib.h>
  EOF
--- 711,717 ----
  rm -f conftest*
  
  cat > conftest.$ac_ext <<EOF
! #line 715 "configure"
  #include "confdefs.h"
  #include <stdlib.h>
  EOF
***************
*** 723,729 ****
  rm -f conftest*
  
  cat > conftest.$ac_ext <<EOF
! #line 727 "configure"
  #include "confdefs.h"
  #include <stdlib.h>
  EOF
--- 725,731 ----
  rm -f conftest*
  
  cat > conftest.$ac_ext <<EOF
! #line 729 "configure"
  #include "confdefs.h"
  #include <stdlib.h>
  EOF
***************
*** 758,764 ****
    ac_cv_c_cross=yes
  else
  cat > conftest.$ac_ext <<EOF
! #line 762 "configure"
  #include "confdefs.h"
  main(){return(0);}
  EOF
--- 760,766 ----
    ac_cv_c_cross=yes
  else
  cat > conftest.$ac_ext <<EOF
! #line 764 "configure"
  #include "confdefs.h"
  main(){return(0);}
  EOF
***************
*** 779,785 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 783 "configure"
  #include "confdefs.h"
  #include <stdlib.h>
  #include <stdarg.h>
--- 781,787 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 785 "configure"
  #include "confdefs.h"
  #include <stdlib.h>
  #include <stdarg.h>
***************
*** 801,807 ****
  if test $ac_cv_header_stdc = yes; then
    # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
  cat > conftest.$ac_ext <<EOF
! #line 805 "configure"
  #include "confdefs.h"
  #include <string.h>
  EOF
--- 803,809 ----
  if test $ac_cv_header_stdc = yes; then
    # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
  cat > conftest.$ac_ext <<EOF
! #line 807 "configure"
  #include "confdefs.h"
  #include <string.h>
  EOF
***************
*** 819,825 ****
  if test $ac_cv_header_stdc = yes; then
    # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
  cat > conftest.$ac_ext <<EOF
! #line 823 "configure"
  #include "confdefs.h"
  #include <stdlib.h>
  EOF
--- 821,827 ----
  if test $ac_cv_header_stdc = yes; then
    # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
  cat > conftest.$ac_ext <<EOF
! #line 825 "configure"
  #include "confdefs.h"
  #include <stdlib.h>
  EOF
***************
*** 840,846 ****
    ac_cv_header_stdc=no
  else
  cat > conftest.$ac_ext <<EOF
! #line 844 "configure"
  #include "confdefs.h"
  #include <ctype.h>
  #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
--- 842,848 ----
    ac_cv_header_stdc=no
  else
  cat > conftest.$ac_ext <<EOF
! #line 846 "configure"
  #include "confdefs.h"
  #include <ctype.h>
  #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
***************
*** 874,880 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 878 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #if STDC_HEADERS
--- 876,882 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 880 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #if STDC_HEADERS
***************
*** 905,911 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 909 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #if STDC_HEADERS
--- 907,913 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 911 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #if STDC_HEADERS
***************
*** 936,942 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 940 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #if STDC_HEADERS
--- 938,944 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 942 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  #if STDC_HEADERS
***************
*** 967,973 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 971 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  EOF
--- 969,975 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 973 "configure"
  #include "confdefs.h"
  #include <sys/types.h>
  EOF
***************
*** 1040,1049 ****
      # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
      eval `make acfindx 2>/dev/null | grep -v make`
      # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR.
!     if test ! -f $ac_im_usrlibdir/libX11.a && test -f $ac_im_libdir/libX11.a
!     then
!       ac_im_usrlibdir=$ac_im_libdir
!     fi
      # Screen out bogus values from the imake configuration.
      case "$ac_im_incroot" in
  	/usr/include) ;;
--- 1042,1053 ----
      # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
      eval `make acfindx 2>/dev/null | grep -v make`
      # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR.
!     for ac_extension in a so sl; do
!       if test ! -f $ac_im_usrlibdir/libX11.$ac_extension &&
!         test -f $ac_im_libdir/libX11.$ac_extension; then
!         ac_im_usrlibdir=$ac_im_libdir; break
!       fi
!     done
      # Screen out bogus values from the imake configuration.
      case "$ac_im_incroot" in
  	/usr/include) ;;
***************
*** 1063,1069 ****
  test -z "$x_direct_test_function" && x_direct_test_function=XtMalloc
  test -z "$x_direct_test_include" && x_direct_test_include=X11/Intrinsic.h
  cat > conftest.$ac_ext <<EOF
! #line 1067 "configure"
  #include "confdefs.h"
  #include <$x_direct_test_include>
  EOF
--- 1067,1073 ----
  test -z "$x_direct_test_function" && x_direct_test_function=XtMalloc
  test -z "$x_direct_test_include" && x_direct_test_include=X11/Intrinsic.h
  cat > conftest.$ac_ext <<EOF
! #line 1071 "configure"
  #include "confdefs.h"
  #include <$x_direct_test_include>
  EOF
***************
*** 1126,1132 ****
  ac_save_LIBS="$LIBS"
  LIBS="-l$x_direct_test_library $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1130 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
--- 1130,1136 ----
  ac_save_LIBS="$LIBS"
  LIBS="-l$x_direct_test_library $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1134 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
***************
*** 1212,1218 ****
  if test "$no_x" = ""; then
      if test "$x_includes" = ""; then
  	cat > conftest.$ac_ext <<EOF
! #line 1216 "configure"
  #include "confdefs.h"
  #include <X11/XIntrinsic.h>
  EOF
--- 1216,1222 ----
  if test "$no_x" = ""; then
      if test "$x_includes" = ""; then
  	cat > conftest.$ac_ext <<EOF
! #line 1220 "configure"
  #include "confdefs.h"
  #include <X11/XIntrinsic.h>
  EOF
***************
*** 1236,1242 ****
      echo checking for X11 header files
      XINCLUDES="# no special path needed"
      cat > conftest.$ac_ext <<EOF
! #line 1240 "configure"
  #include "confdefs.h"
  #include <X11/Intrinsic.h>
  EOF
--- 1240,1246 ----
      echo checking for X11 header files
      XINCLUDES="# no special path needed"
      cat > conftest.$ac_ext <<EOF
! #line 1244 "configure"
  #include "confdefs.h"
  #include <X11/Intrinsic.h>
  EOF
***************
*** 1296,1302 ****
    ac_save_LIBS="$LIBS"
  LIBS="-lXwindow  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1300 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
--- 1300,1306 ----
    ac_save_LIBS="$LIBS"
  LIBS="-lXwindow  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1304 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
***************
*** 1354,1360 ****
    ac_save_LIBS="$LIBS"
  LIBS="-lXbsd  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1358 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
--- 1358,1364 ----
    ac_save_LIBS="$LIBS"
  LIBS="-lXbsd  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1362 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
***************
*** 1387,1393 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1391 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char connect(); below.  */
--- 1391,1397 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1395 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char connect(); below.  */
***************
*** 1435,1441 ****
    ac_save_LIBS="$LIBS"
  LIBS="-lsocket  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1439 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
--- 1439,1445 ----
    ac_save_LIBS="$LIBS"
  LIBS="-lsocket  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1443 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
***************
*** 1471,1477 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1475 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char accept(); below.  */
--- 1475,1481 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1479 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char accept(); below.  */
***************
*** 1517,1523 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1521 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char gethostbyname(); below.  */
--- 1521,1527 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1525 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char gethostbyname(); below.  */
***************
*** 1561,1567 ****
    ac_save_LIBS="$LIBS"
  LIBS="-lnsl  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1565 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
--- 1565,1571 ----
    ac_save_LIBS="$LIBS"
  LIBS="-lnsl  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1569 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
***************
*** 1608,1614 ****
      tk_oldLibs=$LIBS
      LIBS="$LIBS -lX11-mit"
      cat > conftest.$ac_ext <<EOF
! #line 1612 "configure"
  #include "confdefs.h"
  
  	#include <X11/Xlib.h>
--- 1612,1618 ----
      tk_oldLibs=$LIBS
      LIBS="$LIBS -lX11-mit"
      cat > conftest.$ac_ext <<EOF
! #line 1616 "configure"
  #include "confdefs.h"
  
  	#include <X11/Xlib.h>
***************
*** 1650,1656 ****
  
  echo $ac_n "checking count field in FILE structures""... $ac_c" 1>&6
  cat > conftest.$ac_ext <<EOF
! #line 1654 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
--- 1654,1660 ----
  
  echo $ac_n "checking count field in FILE structures""... $ac_c" 1>&6
  cat > conftest.$ac_ext <<EOF
! #line 1658 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
***************
*** 1666,1672 ****
  
  if test "$fcnt" = ""; then
      cat > conftest.$ac_ext <<EOF
! #line 1670 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
--- 1670,1676 ----
  
  if test "$fcnt" = ""; then
      cat > conftest.$ac_ext <<EOF
! #line 1674 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
***************
*** 1683,1689 ****
  fi
  if test "$fcnt" = ""; then
      cat > conftest.$ac_ext <<EOF
! #line 1687 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
--- 1687,1693 ----
  fi
  if test "$fcnt" = ""; then
      cat > conftest.$ac_ext <<EOF
! #line 1691 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
***************
*** 1700,1706 ****
  fi
  if test "$fcnt" = ""; then
      cat > conftest.$ac_ext <<EOF
! #line 1704 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
--- 1704,1710 ----
  fi
  if test "$fcnt" = ""; then
      cat > conftest.$ac_ext <<EOF
! #line 1708 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
***************
*** 1723,1729 ****
  fi
  if test "$fcnt" = ""; then
      cat > conftest.$ac_ext <<EOF
! #line 1727 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
--- 1727,1733 ----
  fi
  if test "$fcnt" = ""; then
      cat > conftest.$ac_ext <<EOF
! #line 1731 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
***************
*** 1750,1756 ****
  fi
  if test "$fcnt" = ""; then
      cat > conftest.$ac_ext <<EOF
! #line 1754 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
--- 1754,1760 ----
  fi
  if test "$fcnt" = ""; then
      cat > conftest.$ac_ext <<EOF
! #line 1758 "configure"
  #include "confdefs.h"
  #include <stdio.h>
  int main() { return 0; }
***************
*** 1794,1800 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1798 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char sin(); below.  */
--- 1798,1804 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1802 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char sin(); below.  */
***************
*** 1841,1847 ****
    ac_save_LIBS="$LIBS"
  LIBS="-lieee  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1845 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
--- 1845,1851 ----
    ac_save_LIBS="$LIBS"
  LIBS="-lieee  $LIBS"
  cat > conftest.$ac_ext <<EOF
! #line 1849 "configure"
  #include "confdefs.h"
  
  int main() { return 0; }
***************
*** 1879,1885 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1883 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char memmove(); below.  */
--- 1883,1889 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1887 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char memmove(); below.  */
***************
*** 1933,1939 ****
      { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
  else
  cat > conftest.$ac_ext <<EOF
! #line 1937 "configure"
  #include "confdefs.h"
  
  int main()
--- 1937,1943 ----
      { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
  else
  cat > conftest.$ac_ext <<EOF
! #line 1941 "configure"
  #include "confdefs.h"
  
  int main()
***************
*** 1979,1985 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1983 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char BSDgettimeofday(); below.  */
--- 1983,1989 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 1987 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char BSDgettimeofday(); below.  */
***************
*** 2023,2029 ****
  
  echo $ac_n "checking for gettimeofday declaration""... $ac_c" 1>&6
  cat > conftest.$ac_ext <<EOF
! #line 2027 "configure"
  #include "confdefs.h"
  #include <sys/time.h>
  EOF
--- 2027,2033 ----
  
  echo $ac_n "checking for gettimeofday declaration""... $ac_c" 1>&6
  cat > conftest.$ac_ext <<EOF
! #line 2031 "configure"
  #include "confdefs.h"
  #include <sys/time.h>
  EOF
***************
*** 2056,2062 ****
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 2060 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char strtod(); below.  */
--- 2060,2066 ----
    echo $ac_n "(cached) $ac_c" 1>&6
  else
    cat > conftest.$ac_ext <<EOF
! #line 2064 "configure"
  #include "confdefs.h"
  /* System header to define __stub macros and hopefully few prototypes,
      which can conflict with char strtod(); below.  */
***************
*** 2102,2108 ****
      { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
  else
  cat > conftest.$ac_ext <<EOF
! #line 2106 "configure"
  #include "confdefs.h"
  
  	extern double strtod();
--- 2106,2112 ----
      { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
  else
  cat > conftest.$ac_ext <<EOF
! #line 2110 "configure"
  #include "confdefs.h"
  
  	extern double strtod();
***************
*** 2221,2227 ****
      echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
      exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
    -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
!     echo "$CONFIG_STATUS generated by autoconf version 2.2"
      exit 0 ;;
    -help | --help | --hel | --he | --h)
      echo "\$ac_cs_usage"; exit 0 ;;
--- 2225,2231 ----
      echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
      exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
    -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
!     echo "$CONFIG_STATUS generated by autoconf version 2.4"
      exit 0 ;;
    -help | --help | --hel | --he | --h)
      echo "\$ac_cs_usage"; exit 0 ;;
***************
*** 2232,2238 ****
  ac_given_srcdir=$srcdir
  ac_given_INSTALL="$INSTALL"
  
! trap 'rm -f Makefile; exit 1' 1 2 15
  
  # Protect against being on the right side of a sed subst in config.status. 
  sed 's/%@/@@/; s/@%/@@/; s/%g$/@g/; /@g$/s/[\\\\&%]/\\\\&/g; 
--- 2236,2242 ----
  ac_given_srcdir=$srcdir
  ac_given_INSTALL="$INSTALL"
  
! trap 'rm -fr `echo "Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
  
  # Protect against being on the right side of a sed subst in config.status. 
  sed 's/%@/@@/; s/@%/@@/; s/%g$/@g/; /@g$/s/[\\\\&%]/\\\\&/g; 
*** ../tk4.0/./library/dialog.tcl	Wed Jun 28 17:15:55 1995
--- ./library/dialog.tcl	Fri Jul 28 09:35:56 1995
***************
*** 3,9 ****
  # This file defines the procedure tk_dialog, which creates a dialog
  # box containing a bitmap, a message, and one or more buttons.
  #
! # @(#) dialog.tcl 1.15 95/06/28 17:15:54
  #
  # Copyright (c) 1992-1993 The Regents of the University of California.
  # Copyright (c) 1994-1995 Sun Microsystems, Inc.
--- 3,9 ----
  # This file defines the procedure tk_dialog, which creates a dialog
  # box containing a bitmap, a message, and one or more buttons.
  #
! # @(#) dialog.tcl 1.16 95/07/28 09:35:57
  #
  # Copyright (c) 1992-1993 The Regents of the University of California.
  # Copyright (c) 1994-1995 Sun Microsystems, Inc.
***************
*** 89,94 ****
--- 89,98 ----
      # 5. Set a grab and claim the focus too.
  
      set oldFocus [focus]
+     set oldGrab [grab current $w]
+     if {$oldGrab != ""} {
+ 	set grabStatus [grab status $oldGrab]
+     }
      grab $w
      tkwait visibility $w
      if {$default >= 0} {
***************
*** 100,109 ****
      # 6. Wait for the user to respond, then restore the focus and
      # return the index of the selected button.  Restore the focus
      # before deleting the window, since otherwise the window manager
!     # may take the focus away so we can't redirect it.
  
      tkwait variable tkPriv(button)
      catch {focus $oldFocus}
      destroy $w
      return $tkPriv(button)
  }
--- 104,121 ----
      # 6. Wait for the user to respond, then restore the focus and
      # return the index of the selected button.  Restore the focus
      # before deleting the window, since otherwise the window manager
!     # may take the focus away so we can't redirect it.  Finally,
!     # restore any grab that was in effect.
  
      tkwait variable tkPriv(button)
      catch {focus $oldFocus}
      destroy $w
+     if {$oldGrab != ""} {
+ 	if {$grabStatus == "global"} {
+ 	    grab -global $oldGrab
+ 	} else {
+ 	    grab $oldGrab
+ 	}
+     }
      return $tkPriv(button)
  }
*** ../tk4.0/./library/listbox.tcl	Thu Jun  8 13:18:30 1995
--- ./library/listbox.tcl	Tue Jul 25 13:24:34 1995
***************
*** 3,9 ****
  # This file defines the default bindings for Tk listbox widgets
  # and provides procedures that help in implementing those bindings.
  #
! # @(#) listbox.tcl 1.11 95/06/04 17:30:09
  #
  # Copyright (c) 1994 The Regents of the University of California.
  # Copyright (c) 1994-1995 Sun Microsystems, Inc.
--- 3,9 ----
  # This file defines the default bindings for Tk listbox widgets
  # and provides procedures that help in implementing those bindings.
  #
! # @(#) listbox.tcl 1.12 95/07/25 13:24:32
  #
  # Copyright (c) 1994 The Regents of the University of California.
  # Copyright (c) 1994-1995 Sun Microsystems, Inc.
***************
*** 79,87 ****
--- 79,89 ----
  }
  bind Listbox <Prior> {
      %W yview scroll -1 pages
+     %W activate @0,0
  }
  bind Listbox <Next> {
      %W yview scroll 1 pages
+     %W activate @0,0
  }
  bind Listbox <Control-Prior> {
      %W xview scroll -1 pages
*** ../tk4.0/./library/menu.tcl	Sun Jun 25 16:11:23 1995
--- ./library/menu.tcl	Fri Jul 28 09:35:56 1995
***************
*** 4,10 ****
  # It also implements keyboard traversal of menus and implements a few
  # other utility procedures related to menus.
  #
! # @(#) menu.tcl 1.51 95/06/25 16:11:23
  #
  # Copyright (c) 1992-1994 The Regents of the University of California.
  # Copyright (c) 1994-1995 Sun Microsystems, Inc.
--- 4,10 ----
  # It also implements keyboard traversal of menus and implements a few
  # other utility procedures related to menus.
  #
! # @(#) menu.tcl 1.52 95/07/28 09:35:55
  #
  # Copyright (c) 1992-1994 The Regents of the University of California.
  # Copyright (c) 1994-1995 Sun Microsystems, Inc.
***************
*** 19,27 ****
--- 19,36 ----
  # cursor -		Saves the -cursor option for the posted menubutton.
  # focus -		Saves the focus during a menu selection operation.
  #			Focus gets restored here when the menu is unposted.
+ # grabGlobal -		Used in conjunction with tkPriv(oldGrab):  if
+ #			tkPriv(oldGrab) is non-empty, then tkPriv(grabGlobal)
+ #			contains either an empty string or "-global" to
+ #			indicate whether the old grab was a local one or
+ #			a global one.
  # inMenubutton -	The name of the menubutton widget containing
  #			the mouse, or an empty string if the mouse is
  #			not over any menubutton.
+ # oldGrab -		Window that had the grab before a menu was posted.
+ #			Used to restore the grab state after the menu
+ #			is unposted.  Empty string means there was no
+ #			grab previously set.
  # popup -		If a menu has been popped up via tk_popup, this
  #			gives the name of the menu.  Otherwise this
  #			value is empty.
***************
*** 236,241 ****
--- 245,251 ----
  	$menu post [winfo rootx $w] [expr [winfo rooty $w]+[winfo height $w]]
      }
      focus $menu
+     tkSaveGrabInfo $w
      grab -global $w
  }
  
***************
*** 302,308 ****
  	}
      }
  
!     # Release grab, if any.
  
      if {$menu != ""} {
  	set grab [grab current $menu]
--- 312,319 ----
  	}
      }
  
!     # Release grab, if any, and restore the previous grab, if there
!     # was one.
  
      if {$menu != ""} {
  	set grab [grab current $menu]
***************
*** 310,315 ****
--- 321,334 ----
  	    grab release $grab
  	}
      }
+     if {$tkPriv(oldGrab) != ""} {
+ 	if {$tkPriv(grabStatus) == "global"} {
+ 	    grab set -global $tkPriv(oldGrab)
+ 	} else {
+ 	    grab set $tkPriv(oldGrab)
+ 	}
+ 	set tkPriv(oldGrab) ""
+     }
  }
  
  # tkMbMotion --
***************
*** 390,397 ****
  # Handles button presses in menus.  There are a couple of tricky things
  # here:
  # 1. Change the posted cascade entry (if any) to match the mouse position.
! # 2. If there is a posted menubutton, must grab to the menubutton so
! #    that it can track mouse motions over other menubuttons and change
  #    the posted menu.
  # 3. If there's no posted menubutton (e.g. because we're a torn-off menu
  #    or one of its descendants) must grab to the top-level menu so that
--- 409,417 ----
  # Handles button presses in menus.  There are a couple of tricky things
  # here:
  # 1. Change the posted cascade entry (if any) to match the mouse position.
! # 2. If there is a posted menubutton, must grab to the menubutton;  this
! #    overrrides the implicit grab on button press, so that the menu
! #    button can track mouse motions over other menubuttons and change
  #    the posted menu.
  # 3. If there's no posted menubutton (e.g. because we're a torn-off menu
  #    or one of its descendants) must grab to the top-level menu so that
***************
*** 411,416 ****
--- 431,437 ----
  		&& [winfo ismapped [winfo parent $menu]]} {
  	    set menu [winfo parent $menu]
  	}
+ 	tkSaveGrabInfo $menu
  	grab -global $menu
      }
  }
***************
*** 811,816 ****
--- 832,853 ----
      }
  }
  
+ # tkSaveGrabInfo --
+ # Sets the variables tkPriv(oldGrab) and tkPriv(grabStatus) to record
+ # the state of any existing grab on the w's display.
+ #
+ # Arguments:
+ # w -			Name of a window;  used to select the display
+ #			whose grab information is to be recorded.
+ 
+ proc tkSaveGrabInfo w {
+     global tkPriv
+     set tkPriv(oldGrab) [grab current $w]
+     if {$tkPriv(oldGrab) != ""} {
+ 	set tkPriv(grabStatus) [grab status $tkPriv(oldGrab)]
+     }
+ }
+ 
  # tk_popup --
  # This procedure pops up a menu and sets things up for traversing
  # the menu and its submenus.
***************
*** 829,834 ****
--- 866,872 ----
  	tkMenuUnpost {}
      }
      tkPostOverPoint $menu $x $y $entry
+     tkSaveGrabInfo $menu
      grab -global $menu
      set tkPriv(popup) $menu
      set tkPriv(focus) [focus]
*** ../tk4.0/./library/tkerror.tcl	Thu Jun  8 13:18:32 1995
--- ./library/tkerror.tcl	Fri Jul 28 09:36:04 1995
***************
*** 4,13 ****
  # posts a dialog box with the error message and gives the user a chance
  # to see a more detailed stack trace.
  #
! # @(#) tkerror.tcl 1.5 95/02/25 13:54:23
  #
  # Copyright (c) 1992-1994 The Regents of the University of California.
! # Copyright (c) 1994 Sun Microsystems, Inc.
  #
  # See the file "license.terms" for information on usage and redistribution
  # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
--- 4,13 ----
  # posts a dialog box with the error message and gives the user a chance
  # to see a more detailed stack trace.
  #
! # @(#) tkerror.tcl 1.6 95/07/28 09:36:05
  #
  # Copyright (c) 1992-1994 The Regents of the University of California.
! # Copyright (c) 1994-1995 Sun Microsystems, Inc.
  #
  # See the file "license.terms" for information on usage and redistribution
  # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
***************
*** 21,34 ****
  
  proc tkerror err {
      global errorInfo
- 
-     # Be sure to release any grabs that might be present on the
-     # screen, since they could make it impossible for the user
-     # to dismiss the error dialog box.
- 
-     if {[grab current .] != ""} {
- 	grab release [grab current .]
-     }
      set info $errorInfo
      set button [tk_dialog .tkerrorDialog "Error in Tcl Script" \
  	    "Error: $err" error 0 OK "Skip Messages" "Stack Trace"]
--- 21,26 ----
***************
*** 64,67 ****
--- 56,67 ----
  	    - [winfo vrooty [winfo parent $w]]]
      wm geom $w +$x+$y
      wm deiconify $w
+ 
+     # Be sure to release any grabs that might be present on the
+     # screen, since they could make it impossible for the user
+     # to interact with the stack trace.
+ 
+     if {[grab current .] != ""} {
+ 	grab release [grab current .]
+     }
  }
*** ../tk4.0/./library/demos/browse	Fri May 26 16:20:57 1995
--- ./library/demos/browse	Tue Jul 18 16:21:45 1995
***************
*** 1,6 ****
  #!/bin/sh
  # the next line restarts using wish \
! exec wish "$0" "$@"
  
  # browse --
  # This script generates a directory browser, which lists the working
--- 1,6 ----
  #!/bin/sh
  # the next line restarts using wish \
! exec wish4.0 "$0" "$@"
  
  # browse --
  # This script generates a directory browser, which lists the working
***************
*** 7,13 ****
  # directory and allows you to open files or subdirectories by
  # double-clicking.
  #
! # @(#) browse 1.5 95/05/26 16:20:51
  
  # Create a scrollbar on the right side of the main window and a listbox
  # on the left side.
--- 7,13 ----
  # directory and allows you to open files or subdirectories by
  # double-clicking.
  #
! # @(#) browse 1.6 95/07/18 16:21:36
  
  # Create a scrollbar on the right side of the main window and a listbox
  # on the left side.
*** ../tk4.0/./library/demos/hello	Fri May 26 16:20:57 1995
--- ./library/demos/hello	Tue Jul 18 16:21:46 1995
***************
*** 1,12 ****
  #!/bin/sh
  # the next line restarts using wish \
! exec wish "$0" "$@"
  
  # hello --
  # Simple Tk script to create a button that prints "Hello, world".
  # Click on the button to terminate the program.
  #
! # @(#) hello 1.3 95/05/26 16:20:52
  # 
  # The first line below creates the button, and the second line
  # asks the packer to shrink-wrap the application's main window
--- 1,12 ----
  #!/bin/sh
  # the next line restarts using wish \
! exec wish4.0 "$0" "$@"
  
  # hello --
  # Simple Tk script to create a button that prints "Hello, world".
  # Click on the button to terminate the program.
  #
! # @(#) hello 1.4 95/07/18 16:21:37
  # 
  # The first line below creates the button, and the second line
  # asks the packer to shrink-wrap the application's main window
*** ../tk4.0/./library/demos/ixset	Fri May 26 16:20:58 1995
--- ./library/demos/ixset	Tue Jul 18 16:21:46 1995
***************
*** 1,6 ****
  #!/bin/sh
  # the next line restarts using wish \
! exec wish "$0" "$@"
  
  # ixset --
  # A nice interface to "xset" to change X server settings
--- 1,6 ----
  #!/bin/sh
  # the next line restarts using wish \
! exec wish4.0 "$0" "$@"
  
  # ixset --
  # A nice interface to "xset" to change X server settings
***************
*** 9,15 ****
  #   91/11/23 : pda@masi.ibp.fr, jt@ratp.fr : design
  #   92/08/01 : pda@masi.ibp.fr : cleaning
  #
! # @(#) ixset 1.4 95/05/26 16:20:53
  
  #
  # Button actions
--- 9,15 ----
  #   91/11/23 : pda@masi.ibp.fr, jt@ratp.fr : design
  #   92/08/01 : pda@masi.ibp.fr : cleaning
  #
! # @(#) ixset 1.5 95/07/18 16:21:37
  
  #
  # Button actions
*** ../tk4.0/./library/demos/rmt	Mon Jun  5 14:41:42 1995
--- ./library/demos/rmt	Tue Jul 18 16:21:46 1995
***************
*** 1,6 ****
  #!/bin/sh
  # the next line restarts using wish \
! exec wish "$0" "$@"
  
  # rmt --
  # This script implements a simple remote-control mechanism for
--- 1,6 ----
  #!/bin/sh
  # the next line restarts using wish \
! exec wish4.0 "$0" "$@"
  
  # rmt --
  # This script implements a simple remote-control mechanism for
***************
*** 7,13 ****
  # Tk applications.  It allows you to select an application and
  # then type commands to that application.
  #
! # @(#) rmt 1.6 95/06/05 14:41:40
  
  wm title . "Tk Remote Controller"
  wm iconname . "Tk Remote"
--- 7,13 ----
  # Tk applications.  It allows you to select an application and
  # then type commands to that application.
  #
! # @(#) rmt 1.7 95/07/18 16:21:38
  
  wm title . "Tk Remote Controller"
  wm iconname . "Tk Remote"
*** ../tk4.0/./library/demos/rolodex	Fri May 26 16:20:58 1995
--- ./library/demos/rolodex	Tue Jul 18 16:21:46 1995
***************
*** 1,6 ****
  #!/bin/sh
  # the next line restarts using wish \
! exec wish "$0" "$@"
  
  # rolodex --
  # This script was written as an entry in Tom LaStrange's rolodex
--- 1,6 ----
  #!/bin/sh
  # the next line restarts using wish \
! exec wish4.0 "$0" "$@"
  
  # rolodex --
  # This script was written as an entry in Tom LaStrange's rolodex
***************
*** 8,14 ****
  # feel of a rolodex program, although it's lifeless and doesn't
  # actually do the rolodex application.
  #
! # @(#) rolodex 1.4 95/05/26 16:20:55
  
  foreach i [winfo child .] {
      catch {destroy $i}
--- 8,14 ----
  # feel of a rolodex program, although it's lifeless and doesn't
  # actually do the rolodex application.
  #
! # @(#) rolodex 1.5 95/07/18 16:21:39
  
  foreach i [winfo child .] {
      catch {destroy $i}
*** ../tk4.0/./library/demos/square	Fri May 26 16:20:58 1995
--- ./library/demos/square	Tue Jul 18 16:21:46 1995
***************
*** 1,6 ****
  #!/bin/sh
  # the next line restarts using wish \
! exec wish "$0" "$@"
  
  # square --
  # This script generates a demo application containing only
--- 1,6 ----
  #!/bin/sh
  # the next line restarts using wish \
! exec wish4.0 "$0" "$@"
  
  # square --
  # This script generates a demo application containing only
***************
*** 11,17 ****
  # Button-1 press/drag:		moves square to mouse
  # "a":				toggle size animation on/off
  #
! # @(#) square 1.3 95/05/26 16:20:56
  
  square .s
  pack .s -expand yes -fill both
--- 11,17 ----
  # Button-1 press/drag:		moves square to mouse
  # "a":				toggle size animation on/off
  #
! # @(#) square 1.4 95/07/18 16:21:41
  
  square .s
  pack .s -expand yes -fill both
*** ../tk4.0/./library/demos/tcolor	Mon Jun  5 22:32:04 1995
--- ./library/demos/tcolor	Tue Jul 18 16:21:46 1995
***************
*** 1,6 ****
  #!/bin/sh
  # the next line restarts using wish \
! exec wish "$0" "$@"
  
  # tcolor --
  # This script implements a simple color editor, where you can
--- 1,6 ----
  #!/bin/sh
  # the next line restarts using wish \
! exec wish4.0 "$0" "$@"
  
  # tcolor --
  # This script implements a simple color editor, where you can
***************
*** 7,13 ****
  # create colors using either the RGB, HSB, or CYM color spaces
  # and apply the color to existing applications.
  #
! # @(#) tcolor 1.7 95/06/05 22:32:03
  
  wm title . "Color Editor"
  
--- 7,13 ----
  # create colors using either the RGB, HSB, or CYM color spaces
  # and apply the color to existing applications.
  #
! # @(#) tcolor 1.8 95/07/18 16:21:42
  
  wm title . "Color Editor"
  
*** ../tk4.0/./library/demos/timer	Fri May 26 16:20:58 1995
--- ./library/demos/timer	Tue Jul 18 16:21:47 1995
***************
*** 1,11 ****
  #!/bin/sh
  # the next line restarts using wish \
! exec wish "$0" "$@"
  
  # timer --
  # This script generates a counter with start and stop buttons.
  #
! # @(#) timer 1.3 95/05/26 16:20:58
  
  label .counter -text 0.00 -relief raised -width 10
  button .start -text Start -command {
--- 1,11 ----
  #!/bin/sh
  # the next line restarts using wish \
! exec wish4.0 "$0" "$@"
  
  # timer --
  # This script generates a counter with start and stop buttons.
  #
! # @(#) timer 1.4 95/07/18 16:21:44
  
  label .counter -text 0.00 -relief raised -width 10
  button .start -text Start -command {
*** ../tk4.0/./library/demos/widget	Wed Jun 21 17:32:39 1995
--- ./library/demos/widget	Tue Jul 18 16:21:45 1995
***************
*** 1,6 ****
  #!/bin/sh
  # the next line restarts using wish \
! exec wish "$0" "$@"
  
  # widget --
  # This script demonstrates the various widgets provided by Tk,
--- 1,6 ----
  #!/bin/sh
  # the next line restarts using wish \
! exec wish4.0 "$0" "$@"
  
  # widget --
  # This script demonstrates the various widgets provided by Tk,
***************
*** 11,17 ****
  # ".tcl" files is this directory, which are sourced by this script
  # as needed.
  #
! # @(#) widget 1.9 95/06/21 17:32:37
  
  eval destroy [winfo child .]
  wm title . "Widget Demonstration"
--- 11,17 ----
  # ".tcl" files is this directory, which are sourced by this script
  # as needed.
  #
! # @(#) widget 1.10 95/07/18 16:21:35
  
  eval destroy [winfo child .]
  wm title . "Widget Demonstration"
*** ../tk4.0/./tests/imgPPM.test	Thu Jun  8 17:04:46 1995
--- ./tests/imgPPM.test	Wed Jul 26 12:58:53 1995
***************
*** 7,13 ****
  # See the file "license.terms" for information on usage and redistribution
  # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  #
! # @(#) imgPPM.test 1.3 95/06/08 17:04:46
  
  if {[info procs test] != "test"} {
      source defs
--- 7,13 ----
  # See the file "license.terms" for information on usage and redistribution
  # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  #
! # @(#) imgPPM.test 1.4 95/07/26 12:58:51
  
  if {[info procs test] != "test"} {
      source defs
***************
*** 44,58 ****
      list [catch {image create photo p1 -file test.ppm} msg] $msg
  } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
  test ppm-1.5 {FileReadPPM procedure} {
      put test.ppm "P6\n10 10\n255\nabcdef"
      list [catch {image create photo p1 -file test.ppm} msg] $msg
  } {1 {error reading PPM image file "test.ppm": not enough data}}
! test ppm-1.6 {FileReadPPM procedure} {
      put test.ppm "P6\n5 4\n255\n01234567890123456789012345678901234567890123456789012345678"
      list [catch {image create photo p1 -file test.ppm} msg] $msg
  } {1 {error reading PPM image file "test.ppm": not enough data}}
! test ppm-1.7 {FileReadPPM procedure} {
!     put test.ppm "P6\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
      list [catch {image create photo p1 -file test.ppm} msg] $msg \
  	    [image width p1] [image height p1]
  } {0 p1 5 4}
--- 44,66 ----
      list [catch {image create photo p1 -file test.ppm} msg] $msg
  } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
  test ppm-1.5 {FileReadPPM procedure} {
+     put test.ppm "P6\n10 20\n256\nabcdef"
+     list [catch {image create photo p1 -file test.ppm} msg] $msg
+ } {1 {PPM image file "test.ppm" has bad maximum intensity value 256}}
+ test ppm-1.6 {FileReadPPM procedure} {
+     put test.ppm "P6\n10 20\n0\nabcdef"
+     list [catch {image create photo p1 -file test.ppm} msg] $msg
+ } {1 {PPM image file "test.ppm" has bad maximum intensity value 0}}
+ test ppm-1.7 {FileReadPPM procedure} {
      put test.ppm "P6\n10 10\n255\nabcdef"
      list [catch {image create photo p1 -file test.ppm} msg] $msg
  } {1 {error reading PPM image file "test.ppm": not enough data}}
! test ppm-1.8 {FileReadPPM procedure} {
      put test.ppm "P6\n5 4\n255\n01234567890123456789012345678901234567890123456789012345678"
      list [catch {image create photo p1 -file test.ppm} msg] $msg
  } {1 {error reading PPM image file "test.ppm": not enough data}}
! test ppm-1.9 {FileReadPPM procedure} {
!     put test.ppm "P6\n5 4\n150\n012345678901234567890123456789012345678901234567890123456789"
      list [catch {image create photo p1 -file test.ppm} msg] $msg \
  	    [image width p1] [image height p1]
  } {0 p1 5 4}
***************
*** 114,120 ****
  } {1 {couldn't recognize data in image file "test.ppm"}}
  test ppm-3.9 {ReadPPMFileHeader procedure} {
      catch {image delete p1}
!     put test.ppm "P6\n5\n255\n012345678901234567890123456789012345678901234567890123456789"
      list [catch {image create photo p1 -file test.ppm} msg] $msg
  } {1 {couldn't recognize data in image file "test.ppm"}}
  test ppm-3.10 {ReadPPMFileHeader procedure} {
--- 122,128 ----
  } {1 {couldn't recognize data in image file "test.ppm"}}
  test ppm-3.9 {ReadPPMFileHeader procedure} {
      catch {image delete p1}
!     put test.ppm "P6\n5\n255\n!012345678901234567890123456789012345678901234567890123456789"
      list [catch {image create photo p1 -file test.ppm} msg] $msg
  } {1 {couldn't recognize data in image file "test.ppm"}}
  test ppm-3.10 {ReadPPMFileHeader procedure} {
***************
*** 122,133 ****
      put test.ppm "P6\n5 4\nzz255\n012345678901234567890123456789012345678901234567890123456789"
      list [catch {image create photo p1 -file test.ppm} msg] $msg
  } {1 {couldn't recognize data in image file "test.ppm"}}
- test ppm-3.11 {ReadPPMFileHeader procedure} {
-     catch {image delete p1}
-     put test.ppm "P6\n5 4\n254\n012345678901234567890123456789012345678901234567890123456789"
-     list [catch {image create photo p1 -file test.ppm} msg] $msg
- } {1 {couldn't recognize data in image file "test.ppm"}}
- 
  
  catch {exec rm test.ppm}
  catch {exec rm test2.ppm}
--- 130,135 ----
